﻿/**
 * ...
 * @author js
 */

package tab;

import flash.events.KeyboardEvent;
import flash.Lib;
import flash.text.TextField;
import flash.text.TextFieldType;
import gui.hug.HUGInputFieldSB;
import gui.hug.HUGSprite;
import gui.hug.HUGTabbedPanel;
import gui.hug.Tab;

import list.NewList;
import list.OpenTabEvent;

import loader.Loader;

import client.Channel;

class FindTag extends Tab
{
	private static inline var 	TITLE = "Поиск по категориям";
	
	private var loader : 	Loader;
	private var newsList : 	NewList;
	private var inp : TextField;
	private var sprite : HUGSprite;
	
	public function new(panel : HUGTabbedPanel = null, uid : Int = 0) 
	{
		
	 sprite = new HUGSprite();	
	 loader = new Loader(uid);
	
	inp = new TextField();
	
	inp.x = inp.y = 10;
	inp.height = 20;
	inp.width = 400;
	inp.type = TextFieldType.INPUT;
	inp.border = true;
	sprite.addChild(inp);
	newsList = new NewList(10, 31, 600);
	Lib.current.addEventListener(KeyboardEvent.KEY_DOWN, hitEnter);
	
	super(sprite, TITLE, panel, true);
	}
	
    
    function hitEnter(event:KeyboardEvent)
    {
        if (event.keyCode == 13 && inp.text != "")
        {
            loader.FindTag(onLoad, inp.text);
			
        }
    }
	
	public function onLoad(data : Array<Channel>) : Void
	{
		for (channel in data)
		{
			newsList.addItem(channel);
		}
	}	
	
}

